#ifndef H_RCGD_RB_H
#define H_RCGD_RB_H   

#define	RB_STATUS_NONE	0
#define	RB_STATUS_SET	1
#define	RB_STATUS_RUN	2

#define 	RB_NO_SAVE			0
#define 	RB_SAVE				1

#define	RB_TRACK_NEVER		0	//Don't Track
#define	RB_TRACK_NOW		1	//Track Now
#define	RB_TRACK_EVER		2	//Track after Reset or Power On
#define	RB_TRACK_NOW_EVER	3
#define	RB_TRACK_STATUS	9	//Interrogation

#define	RB_SYNC_NEVER		0	//Don't Synchronization
#define	RB_SYNC_NOW			1	//Sync Now
#define	RB_SYNC_EVER		2	//Sync after Reset or Power On
#define	RB_SYNC_NOW_EVER	3
#define	RB_SYNC_STATUS		9	//Interrogation

#define 	RB_WARMING_UP					0	//This happens when the SRO is just powered on and the temperature of the cells is not high enough.
#define 	RB_TRACKING_SETUP				1	//The SRO is in this state when it goes from free-run status to the track status after a track set-up. The duration of this state should not exceed 3 minutes.
#define 	RB_TRACK_TO_PPSREF			2	//PPSINT is aligned to PPSREF.
#define 	RB_SYNC_TO_PPSREF				3	//PPSINT and PPSOUT are aligned to PPSREF.
#define 	RB_FREERUN_TRACKOFF			4	//Track off.
#define 	RB_FREERUN_PPSREF_UNSTABLE	5	//PPSREF unstable. The stability of the PPSREF is too low to be tracked.
#define 	RB_FREERUN_NO_PPSREF			6	//No PPSREF was detected.
#define 	RB_FAULT_OUT_OFF_LOCK		9	//This happens when the VCXO is scanning to find the Rb line.


#define	RB_BEAT_DATE		A	//Beat Date, Time, Counter data in NMEA 0183 proprietary format
#define	RB_BEAT_FREQ		B	//Beat Frequencies, Tra. loop parameters in NMEA 0183 proprietary format

typedef struct{
	int print_Flag;
	int Error_counter;

	int FC_value;			//FCsddddd value
	int prev_FC_value;	//FCsddddd value
	int FC_diff;

	int quality;			//timing quality indicator, 0: Rb line not locked, 1: Free Run, 2: Disciplined
	int T3;					//format of the following 5 data. T3 means:
	int time_interval;	//time interval PPSREF vs PPSOUT, from 0000000 to 7499999 in 133 ns steps
	int phase_compare;	//phase comparator, from –511 to +512, in approx. 1 ns steps
	int general_status;	//general SRO status

} sro100_;

typedef struct{
	int IntervalCounter;
	char status;
	char comm_ready;
	int tx_counter;
	int tx_error;
	char tx_flag;

	sro100_ sro100;//Rb-SRO-100 Sewon
} rb_;


extern rb_	rb;

extern void Init_rb();
extern void Rb_Task();
extern void DecodeRbCommand(BYTE*,int);
extern void SetRbFreq(void);

extern void Rb_Comm_ID(void);
extern void Rb_Comm_SN(void);
extern void Rb_Comm_M(void);
extern void Rb_Comm_ST(void);
extern void Rb_Comm_TRx(int track_mode);
extern void Rb_Comm_DEddddddd(int delay);
extern void Rb_Comm_TD(int hour,int min,int sec);
extern void Rb_Comm_BTx(int mode);
extern void FCsddddd(int value);
extern void FSx(int value);
extern void COsddd(int value);
extern void RAsddd(int value);
#endif
